package com.ruoyi.common.websocket;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.springframework.web.socket.TextMessage;

import java.util.Date;

@Data
public class WebSocketMessage {

    public static final String ROOM_TEXT = "ROOM_TEXT";
    public static final String ROOM_JOIN = "ROOM_JOIN";
    public static final String ROOM_CREATE = "ROOM_CREATE";
    public static final String WUZIQI = "WUZIQI";

    private String messageId;

    private String messageType;

    private String message;

    private String from;

    private String to;

    private String status;

    private Date createTime;

    public static WebSocketMessage init(TextMessage textMessage) {
        String jsonString = textMessage.getPayload();
        return JSON.parseObject(jsonString, WebSocketMessage.class);
    }

    public TextMessage toTextMessage() {
       String jsonString = JSONObject.toJSONString(this);
       return new TextMessage(jsonString);
    }
//
//    public void setDefaultMessage(String message) {
//        this.message = new TextMessageBody(message).serializeMessage();
//    }
//
//    public void setMessage(MessageBody message) {
//        this.message = message.serializeMessage();
//    }
//
//    public static class TextMessageBody extends MessageBody{
//
//        public TextMessageBody(String message) {
//            this.messageText = message;
//        }
//
//        @Override
//        public String serializeMessage() {
//            return messageText;
//        }
//    }
//
//    public abstract static class MessageBody{
//
//        protected String messageText;
//
//        public abstract String serializeMessage();
//    }

}
